<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.ORM.entity.chainS.inventoryFlow.ChainInventoryFlowOrder"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>千禧宝贝连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>

<script>
var formSubmit = false;
var P_NUMBER = 2;
var N_PRINT = 1;
var P_DISCOUNT = 3;
var index = 0;

//constants
var SALES_ORDER = 1;
var RETURN_ORDER = 2;

var errorIndexes = new Array();

document.onkeydown = BSkeyDown; 
function BSkeyDown(e){

	 var ieKey = event.keyCode;
	 //enter key is pressed 
	 if (ieKey==13){
	   if (event.srcElement.id.substring(0,7)=="barcode"){
           var index_trigger = event.srcElement.id.substring(7); 

		   var currentBarcode =$("#barcode"+index_trigger).val();
	       event.returnValue=false;
	
	       retrieveProductByBarcode(index_trigger,"" , currentBarcode);
	   } else if (event.srcElement.id.substring(0,11)=="productCode"){
		   var index_trigger = event.srcElement.id.substring(11);
		   event.returnValue=false;
		   searchProductsProductCode(index_trigger);
	   }else
		   event.returnValue=false;
	    
	 //back space key
	 }  else if (ieKey==8){
		    if((event.srcElement.tagName.toLowerCase() == "input" && event.srcElement.readOnly != true) || event.srcElement.tagName.toLowerCase() == "textarea"){
		        event.returnValue = true; 
		    } else
		    	event.returnValue = false;
	 }
} 


/**
 * user input the product code and press enter
 */
function searchProductsProductCode(index_trigger){
	
	var productCode = $.trim($("#productCode" +index_trigger).val());
	var storeId = $("#storeId").val();
	if (validateProductCodeInput(productCode)){
//	    var url = encodeURI(encodeURI("actionChain/chainSalesJSPAction!scanByProductCode?" + "formBean.productCode=" + productCode + "&formBean.index=" + index_trigger +"&formBean.chainId=" + $("#chainStore").val())) ;
	    
	    var params= "formBean.productBarcode.product.productCode=" + productCode + "&formBean.storeId=" + storeId + "&formBean.indexPage=" + index_trigger + "&formBean.fromSrc=1"; 
	    
	    var url = encodeURI(encodeURI("productJSPAction!scanByProductCodeHeadq?" +params)) ; 
		
	    window.open(url,'新窗口','height=530, width=700, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');    
	}
}

/**
 * retrieve the product by input barcode
 */
function retrieveProductByBarcode(index_trigger, suffix, currentBarcode){
	
	if (validateRowInput(index_trigger,currentBarcode)){		

	    
	    var storeId = $("#storeId").val();
	    var params= "formBean.pb.barcode=" + currentBarcode + "&formBean.indexPage=" + index_trigger+ "&formBean.storeId="+storeId ; 
	    $.post("action/headqInventoryFlowJSONAction!scanByBarcodeInvenFlowOrder",params, backRetrievePByBarcodeProcess,"json");

	}
}

/**
 * to validate the product code input
 */
function validateProductCodeInput(productCode){
	if (productCode.length <= 1){
       alert("输入的货号太短");
       return false;
	}
	return true;
}


/**
 * to clear the corresponding row's data
 */
function clearRowCells(index_c){
	//clear the cell
	$("#productId" +index_c).attr("value","");  
   	$("#unit" +index_c).attr("value","");  
	$("#brand" +index_c).attr("value","");   
	$("#productCode"+index_c).attr("value",0); 
	$("#quantity"+index_c).attr("value",0); 
	$("#comment"+index_c).attr("value",""); 
	$("#barcode"+index_c).attr("value",""); 
	$("#year"+index_c).attr("value",""); 
	$("#quarter"+index_c).attr("value",""); 
	$("#inventoryQ"+index_c).attr("value",""); 
	calculateTotal();
}




function deleteRow(rowID){
	$("#"+rowID).remove(); 
 	calculateTotal();
    
}

function deleteOrder(){
	if (confirm("你确定删除此单据吗?")){
		   formSubmit = true;
		   document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!deleteOrder";
		   document.chainInventoryFlowForm.submit();
	}
}
$(document).ready(function(){
	parent.$.messager.progress('close'); 
});
var baseurl = "<%=request.getContextPath()%>";
index = parseInt("<s:property value='formBean.flowOrder.productList.size()'/>");
function downloadOrder(){
	
    document.chainInventoryFlowForm2.action="inventoryFlowJSPAction!downloadFlowOrder";
    document.chainInventoryFlowForm2.submit();
}





function validateInvenFlowForm(type){
	  if (confirm("你确认提交单据?")){

			var error = "";

			var hasChar_q = false;

			for (var i = 0; i < index; i++){

				var q = $("#quantity" + i).val();

				if (q != undefined){
					if (isNaN(q) || q==0){
						hasChar_q = true;
						errorIndexes.push(i);
					}
				}
			}
			
			if (hasChar_q)
				error += "数量 - 必须为大于0的整数. 请检查后重新输入!\n";

			if (error != ""){
				for (var i =0; i < errorIndexes.length; i++){
					$("#orderRow" + errorIndexes[i]).css('background-color', '#EE8553');
				}
				
				alert(error);
				return false;
			}else{
				var totalQ = $("#totalQuantity").val();
				if (totalQ =="" || totalQ==0){
					alert("请输入货品后再保存单据!");
					return false;
				} 
            return true;
			}
	    } else {
	    	return false;
	    }
}


function backRetrievePByBarcodeProcess(data){
	var error = data.error;
	var index_c = data.returnValue.indexC;

	if (error == true){
    	var errorRow = $("#orderRow"+index_c);
    	if (errorRow.length != 0){
    	  errorRow.css('background-color', '#EE8553');
		  clearRowCells(index_c);
    	}
	}else{
		var scanType = $("#scanType").is(':checked');
		var productIdInput =  $("#productId" +index_c);  
       	var unitInput =  $("#unit" +index_c);  
    	var brandInput =  $("#brand" +index_c);   
    	var categoryInput = $("#category" +index_c);
    	var productCodeInput = $("#productCode"+index_c); 
    	var quantityInput =  $("#quantity"+index_c); 
    	var barcodeInput = $("#barcode"+index_c); 
    	var yearInput = $("#year"+index_c); 
    	var quarterInput = $("#quarter"+index_c); 
    	var inventoryInput = $("#inventoryQ"+index_c); 
    	var quantityDiffInput = $("#quantityDiff"+index_c); 
    	var colorInput = $("#color"+index_c); 
    	var salesPriceInput = $("#salesPrice" + index_c);
    	var totalCostInput = $("#totalCost" + index_c);
    	
		var barcode = data.returnValue.pb.barcode;
		var productId = data.returnValue.pb.id;
		var product = data.returnValue.pb.product;
		var productCode = product.productCode;
		var brand = product.brand.brand_Name;
		var category = product.category.category_Name;  // 货品类别
		var unit = product.unit;
		var quantity = 1;
		if (scanType)
		    quantity = product.numPerHand;

		var year = product.year.year;
		var quarter = product.quarter.quarter_Name;
		var inventoryQ = data.returnValue.inventoryLevel;
		var color = data.returnValue.pb.color;
		var colorName = "";

		if (color != null)
    		colorName = color.name;
		
		var salesPrice = product.salesPrice;
		var totalCost = quantity * salesPrice;

		productIdInput.attr("value",productId);
		barcodeInput.attr("value",barcode);
		productCodeInput.attr("value",productCode);
		unitInput.attr("value",unit);
    	brandInput.attr("value",brand); 
    	categoryInput.attr("value",category);
    	quantityInput.attr("value",quantity); 
    	yearInput.attr("value",year); 
    	quarterInput.attr("value",quarter); 
    	inventoryInput.attr("value", inventoryQ);
    	quantityDiffInput.attr("value", quantity - inventoryQ);
    	colorInput.attr("value", colorName);
    	salesPriceInput.attr("value", salesPrice);
    	totalCostInput.attr("value", totalCost);
    	
    	calculateTotal();
    	
    	var row = $("#orderRow"+index_c);
    	row.css('background-color', '');
	}
	
	//if the user just changed the original barcode information
	//then no need to add the index by one
	if (index_c == index){
	   addNewRow();
	} else 
       $("#barcode"+index).focus(); 

}

/**
 * to calculate the total value for the quantity
 */
function calculateTotal(){
	var quantity_t =0;
	var inventory_t = 0;
	var quantityDiff_t = 0;
	var totalCostOrder = 0;

	for (var i = 0; i <= index; i++){
	   	var quantityInput =  $("#quantity"+i); 
	   	var inventoryInput =  $("#inventoryQ"+i); 
	   	var quantityDiffInput =  $("#quantityDiff"+i); 
	   	var salesPriceInput = $("#salesPrice"+i); 
	   	var totalCostInput = $("#totalCost"+i); 
	   	
        if (quantityInput.val()!= undefined && quantityInput.val()!="" ){
		   quantity_t += parseInt(quantityInput.val());
        }
        if (inventoryInput.val()!= undefined && inventoryInput.val()!=""){
        	inventory_t += parseInt(inventoryInput.val());
        }
        
        if (quantityInput.val()!= undefined && inventoryInput.val()!= undefined){
	        var diff = quantityInput.val() - inventoryInput.val();
	        quantityDiffInput.attr("value", diff);
	        quantityDiff_t += parseInt(diff);
        }
        if (quantityInput.val()!= undefined && quantityInput.val()!="" && salesPriceInput.val()!= undefined && salesPriceInput.val()!=""){
        	var totalCost = parseInt(quantityInput.val()) * salesPriceInput.val();
        	totalCostInput.attr("value", totalCost);
        	totalCostOrder += totalCost;
        }
	}

   	$("#totalQuantity").attr("value",quantity_t); 
   	$("#totalInventoryQ").attr("value",inventory_t); 
   	$("#totalQuantityDiff").attr("value",quantityDiff_t);
   	$("#totalCostOrder").attr("value",totalCostOrder); 
}

/**
 * once the quantity is changed, it will trigger this function
 * @param indexQ
 */
function changeQuantity(indexQ){
	
}

function addNewRow(){
    index = index +1;
	var pre_index = index -1;
	$("#viewIcon"+pre_index).show();
	$("#delIcon"+pre_index).show();
    var str = "";
    str += "<tr class='InnerTableContent' id='orderRow"+index+"'>";   
    str += "<td height='25'>"+(index +1)+"</td>";  
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.barcode' id='barcode"+index+"' size='13'/>" +
               "<input type='hidden' name='formBean.flowOrder.productList["+index+"].productBarcode.id' id='productId"+index+"' size='13'/></td>";  
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.product.productCode' id='productCode"+index+"' size='13'/></td>";  
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.color.name' id='color"+index+"' size='5'/></td>"; 
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.product.brand.brand_Name' id='brand"+index+"'  size='17' readonly='readonly'/></td>";
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.product.category.category_Name' id='category"+index+"'  size='17' readonly='readonly'/></td>";
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.product.year.year' id='year"+index+"'  size='4' readonly='readonly'/></td>"; 
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.product.quarter.quarter_Name' id='quarter"+index+"'  size='4' readonly='readonly'/></td>"; 
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.product.unit' id='unit"+index+"' size='4' readonly='readonly'/></td>";  
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].productBarcode.product.salesPrice' id='salesPrice"+index+"'  size='2' readonly='readonly'/></td>";
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].quantity' id='quantity"+index+"'  size='2' onchange='calculateTotal("+index+")' onkeypress='return is_number(event);'/></td>";  
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].totalCost' id='totalCost"+index+"'  size='2' readonly='readonly'/></td>"; 
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].inventoryQ' id='inventoryQ"+index+"' readonly  size='2' onchange='calculateTotal("+index+")'/></td>";
    str += "<td><input type='text' name='formBean.flowOrder.productList["+index+"].quantityDiff' id='quantityDiff"+index+"'  size='2'/></td>";  
    str += "<td><div id='viewIcon"+index+"' style='display:none'><img src='"+baseurl+"/conf_files/web-image/search.png' border='0'  onclick='viewImgByInventory(\""+index +"\");' style='cursor:pointer;'/></div></td>";  
    str += "<td><div id='delIcon"+index+"' style='display:none'><img src='"+baseurl+"/conf_files/web-image/delete.png' border='0'  onclick='deleteRow(\"orderRow"+index +"\");' style='cursor:pointer;'/></div></td>";  
    str += "</tr>";   

    $("#orderTablebody").append(str);

    //freeze the previous row
    var barcodeInput = $("#barcode"+pre_index);
    barcodeInput.attr("readonly",true);
    
    var productCodeInput = $("#productCode"+pre_index);
    productCodeInput.attr("readonly",true);
    
	$("#barcode"+index).focus(); 
}


/**
 * 根据条码查询图片详情
 */
function viewImgByInventory(rowID){
	var barcode =  $("#barcode" + rowID).val();  
	viewImg(barcode);
}

/**
 * to validate whether the product is selected or not
 */
function validateRowInput(index_trigger,currentBarcode){
	for (var i = 0; i < index; i++){
		if (i != index_trigger){
			var barcodeInput =  $("#barcode"+i);
	
			if (currentBarcode == barcodeInput.val()){
				var currentQ = $("#quantity" +i).val();
				$("#quantity" +i).attr("value" , parseInt(currentQ) + 1);
				
				calculateTotal();
				
				$("#barcode"+index).attr("value",""); 
		    	$("#barcode"+index).focus(); 
				
				return false;
			}
		}
	}
	return true;
}

/**
 * to validate whether the product is selected or not
 * this is called from child
 */
function validateRowInputFromChild(currentBarcode){
	return true;
}
/**
 * actions
 */
function calInventoryOrder(){
	var file = $("#inventory").val();
	if (file != ""){
	  var confirmMsg = "计算库存将忽略上传的盘点文件,你要继续吗?";
		var con = confirm(confirmMsg);
		if(con == true){
		   var afile = $("#inventory");
		   afile.replaceWith(afile.clone());
		} else
		   return;
	}

   if (validateInvenFlowForm(false)){
		parent.$.messager.progress({
			text : '数据处理中，请稍后....'
		});
      formSubmit = true;
      document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!calculateInventoryOrder";
      document.chainInventoryFlowForm.submit();
   }
}
/**
 * actions
 */
function genInventoryReport(){
	var msg = "生成库存报表后，将不能再修改，是否继续?";

	if (confirm(msg) && validateInvenFlowForm(false)){
		parent.$.messager.progress({
			text : '数据处理中，请稍后....'
		});
	   formSubmit = true;
	   document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!genInventoryReport";
	   document.chainInventoryFlowForm.submit();
	}
}

function oneKeyToAdjustInventory(){
	var file = $("#inventory").val();
	if (file != ""){
	  var msg = "如果有盘点文件，请先上传文件然后保存到草稿中.";
	  $.messager.alert('确认信息', msg,"info");
	} else if (confirm("你确定上传货品的实际库存已经正确.一键纠正库存将根据当前实际库存，纠正单据中物品电脑库存.继续?") && validateInvenFlowForm(false)){
		parent.$.messager.progress({
			text : '数据处理中，此功能耗时较长.请稍后....'
		});
	   formSubmit = true;
	   document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!oneKeyAdjustInventory";
	   document.chainInventoryFlowForm.submit();
	}
}

function oneKeyToClearAndAdjustInventory(){
	var file = $("#inventory").val();
	if (file != ""){
	  var msg = "如果有盘点文件，请先上传文件然后保存到草稿中.";
	  $.messager.alert('确认信息', msg,"info");
	} else{
		if (validateInvenFlowForm(false)){
			parent.$.messager.progress({
				text : '数据处理中，请稍后....'
			});
	        var params = $("#chainInventoryFlowForm").serialize(); 
		    $.post("headqInventoryFlowJSONAction!getYearQuarterInFlowOrder",params, oneKeyToClearAndAdjustInventoryBK,"json");
	    }
	}
}

function oneKeyToClearAndAdjustInventoryBK(data){
	parent.$.messager.progress('close'); 
	var response = data.response;
	var returnCode = response.returnCode;
	if (returnCode == SUCCESS){
		var confirmMsg ="请确定此单据中只包含了如下季度货品: " + response.returnValue + "\n\n" +
						"此功能将使用单据中的实际库存完全取代连锁店的电脑库存.请确认这张单据里面的季度是你这次盘点所包含的季度吗?";
		if (confirm(confirmMsg)){
			parent.$.messager.progress({
				text : '数据处理中，此功能耗时较长.请稍后....'
			});
		   formSubmit = true;
		   document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!oneKeyClearAndAdjustInventory";
		   document.chainInventoryFlowForm.submit();
		}
	} else {
		alert("获取货品季度出现出错，请稍后再试");
	}
}

/**
 * 把条码保存下来
 */
function getBarcodeFile(){
	formSubmit = true;
	document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!getBarcodeFile";
	document.chainInventoryFlowForm.submit();	
}
/**
 * actions
 */
function saveDraft(){
	if (validateInvenFlowForm(true)){
		parent.$.messager.progress({
			text : '数据处理中，请稍后....'
		});
	   formSubmit = true;
	   document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!saveInventoryToDraft";
	   document.chainInventoryFlowForm.submit();
	}
}
function saveFinal(){
	if (validateInvenFlowForm(true)){
			parent.$.messager.progress({
				text : '数据处理中，请稍后....'
			});
		   formSubmit = true;
		   document.chainInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!saveInventoryToFinal";
		   document.chainInventoryFlowForm.submit();
	}
}





</script>
</head>
<body>
	<%@ include file="../../common/loadingDiv.jsp"%>
	<s:form action="/action/headqInventoryFlowJSPAction!saveToDraft"
		method="POST" name="chainInventoryFlowForm"
		id="chainInventoryFlowForm" enctype="multipart/form-data"
		theme="simple">
		<s:hidden name="formBean.flowOrder.type" />
		<s:hidden name="formBean.flowOrder.id" />
		<s:hidden name="formBean.flowOrder.status" />
		<table width="90%" align="center" class="OuterTable">
			<tr>
				<td>
					<div class="errorAndmes">
						<s:actionerror cssStyle="color:red" />
						<s:actionmessage cssStyle="color:blue" />
					</div>
					<table width="100%" border="0">
						<tr>
							<td height="50" colspan="7">
								<table width="100%" border="0">
									<tr class="PBAOuterTableTitale">
										<td height="50" colspan="5"><s:property
												value="formBean.flowOrder.typeChainS" /><br />
										<br /> - 用户扫描仓库库存货品获取目前实际库存</td>
									</tr>
									<tr class="InnerTableContent">
										<td><strong>库房:</strong>
										<s:select style="left:20px;position:relative"
												name="formBean.flowOrder.storeId" size="1" id="storeId"
												list="uiBean.stores" listKey="id" listValue="name" /></td>
										<td width="160">创建人:<s:property
												value="formBean.flowOrder.creator.name" /></td>
										<td width="300">日期:<s:property
												value="formBean.flowOrder.orderDate" /></td>
										<td width="200">状态:<s:property
												value="formBean.flowOrder.statusS" /></td>
										<td width="200"></td>
									</tr>
								</table>
							</td>
						</tr>
						<tr class="InnerTableContent">
							<td colspan="7"><hr width="100%" color="#FFCC00" /></td>
						</tr>
						<tr>
							<td colspan="7">
								<!-- table to display the product information -->
								<table width="100%" align="left" class="OuterTable"
									id="org_table">
									<tr class="PBAInnerTableTitale" align='left'>
										<th width="21">&nbsp;</th>
										<th width="93" height="35">条形码</th>
										<th width="93">货号/名称</th>
										<th width="40">颜色</th>
										<th width="102">品牌</th>
										<th width="80">货品类别</th>
										<th width="40">年份</th>
										<th width="40">季度</th>
										<th width="40">单位</th>
										<th width="45">零售单价<br />A
										</th>
										<th width="45">实际数量<br />B
										</th>
										<th width="45">零售额<br />A*B
										</th>
										<th width="52">电脑库存<br />C
										</th>
										<th width="30">差额<br />B-C
										</th>
										<th width="20">图片</th>
										<th width="20"></th>
									</tr>
									<tbody id="orderTablebody">
										<s:iterator value="formBean.flowOrder.productList" status="st"
											id="orderProduct">
											<tr class="InnerTableContent"
												id="orderRow<s:property value="#st.index"/>">
												<td height="25"><s:property value="#st.index +1" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.barcode"
													id="barcode<s:property value="#st.index"/>" size="13"
													value="<s:property value="#orderProduct.productBarcode.barcode"/>" />
													<input type="hidden"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].id"
													size="13" value="<s:property value="#orderProduct.id"/>" />
													<input type="hidden"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.Id"
													size="13"
													value="<s:property value="#orderProduct.productBarcode.Id"/>" />
												</td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.product.productCode"
													id="productCode<s:property value="#st.index"/>" size="13"
													value="<s:property value="#orderProduct.productBarcode.product.productCode"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.color.name"
													id="color<s:property value="#st.index"/>" size="5"
													value="<s:property value="#orderProduct.productBarcode.color.name"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.product.brand.brand_Name"
													id="brand<s:property value="#st.index"/>" size="17"
													readonly
													value="<s:property value="#orderProduct.productBarcode.product.brand.brand_Name"/>" /></td>	
												<td><input type="text" name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.product.category.category_Name" 
													id="category<s:property value="#st.index"/>"  size="17" readonly
												 	value="<s:property value="#orderProduct.productBarcode.product.category.category_Name"/>"/></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.product.year.year"
													id="year<s:property value="#st.index"/>" size="4" readonly
													value="<s:property value="#orderProduct.productBarcode.product.year.year"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.product.quarter.quarter_Name"
													id="quarter<s:property value="#st.index"/>" size="4"
													readonly
													value="<s:property value="#orderProduct.productBarcode.product.quarter.quarter_Name"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.product.unit"
													id="unit<s:property value="#st.index"/>" size="4" readonly
													value="<s:property value="#orderProduct.productBarcode.product.unit"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].productBarcode.product.salesPrice"
													id="salesPrice<s:property value="#st.index"/>" size="2"
													readonly="readonly"
													value="<s:property value="#orderProduct.productBarcode.product.salesPrice"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].quantity"
													id="quantity<s:property value="#st.index"/>" size="2"
													onchange="calculateTotal()"
													onkeypress="return is_number(event);"
													value="<s:property value="#orderProduct.quantity"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].totalCost"
													id="totalCost<s:property value="#st.index"/>"
													size="2" readonly="readonly"
													value="<s:property value="#orderProduct.totalCost"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].inventoryQ"
													id="inventoryQ<s:property value="#st.index"/>" size="2"
													readonly onchange="calculateTotal()"
													onkeypress="return is_number(event);"
													value="<s:property value="#orderProduct.inventoryQ"/>" /></td>
												<td><input type="text"
													name="formBean.flowOrder.productList[<s:property value="#st.index"/>].quantityDiff"
													id="quantityDiff<s:property value="#st.index"/>" size="2"
													readonly
													value="<s:property value="#orderProduct.quantityDiff"/>" /></td>
												<td><div id="viewIcon<s:property value="#st.index"/>"
														style="display: block">
														<img
															src="<%=request.getContextPath()%>/conf_files/web-image/search.png"
															border="0"
															onclick="viewImgByInventory('<s:property value="#st.index"/>');"
															style="cursor: pointer;" />
													</div></td>	
												<td><div id="delIcon<s:property value="#st.index"/>"
														style="display: block">
														<img
															src="<%=request.getContextPath()%>/conf_files/web-image/delete.png"
															border="0"
															onclick="deleteRow('orderRow<s:property value="#st.index"/>');"
															style="cursor: pointer;" />
													</div></td>
											</tr>
										</s:iterator>
										<tr class="InnerTableContent"
											id="orderRow<s:property value='formBean.flowOrder.productList.size()'/>">
											<td height="25"><s:property
													value='formBean.flowOrder.productList.size() + 1' /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.barcode"
												id="barcode<s:property value='formBean.flowOrder.productList.size()'/>"
												size="13" /> <input type="hidden"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.id"
												id="productId<s:property value='formBean.flowOrder.productList.size()'/>"
												size="13" /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.product.productCode"
												id="productCode<s:property value='formBean.flowOrder.productList.size()'/>"
												size="13" /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.color.name"
												id="color<s:property value='formBean.flowOrder.productList.size()'/>"
												size="5" /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.product.brand.brand_Name"
												id="brand<s:property value='formBean.flowOrder.productList.size()'/>"
												size="17" readonly /></td>
											<td><input type="text" name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.product.category.category_Name" id="category<s:property 
												value='formBean.flowOrder.productList.size()'/>" 
												 size="17" readonly/></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.product.year.year"
												id="year<s:property value='formBean.flowOrder.productList.size()'/>"
												size="4" readonly /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.product.quarter.quarter_Name"
												id="quarter<s:property value='formBean.flowOrder.productList.size()'/>"
												size="4" readonly /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.product.unit"
												id="unit<s:property value='formBean.flowOrder.productList.size()'/>"
												size="4" readonly /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].productBarcode.product.salesPrice"
												id="salesPrice<s:property value='formBean.flowOrder.productList.size()'/>"
												size="2" readonly="readonly" /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].quantity"
												id="quantity<s:property value='formBean.flowOrder.productList.size()'/>"
												size="2" onchange="calculateTotal()"
												onkeypress="return is_number(event);" /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].totalCost"
												id="totalCost<s:property value='formBean.flowOrder.productList.size()'/>"
												size="2" readonly="readonly" /></td>
											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].inventoryQ"
												id="inventoryQ<s:property value='formBean.flowOrder.productList.size()'/>"
												size="2" onchange="calculateTotal()"
												onkeypress="return is_number(event);" /></td>

											<td><input type="text"
												name="formBean.flowOrder.productList[<s:property value='formBean.flowOrder.productList.size()'/>].quantityDiff"
												id="quantityDiff<s:property value='formBean.flowOrder.productList.size()'/>"
												readonly size="2" /></td>
											<td><div id="viewIcon<s:property value='formBean.flowOrder.productList.size()'/>" style="display: none">
												<img src="<%=request.getContextPath()%>/conf_files/web-image/search.png" border="0" onclick="viewImgByInventory('<s:property value='formBean.flowOrder.productList.size()'/>');" style="cursor: pointer;" />
												</div></td>
											<td><div
													id="delIcon<s:property value='formBean.flowOrder.productList.size()'/>"
													style="display: none">
													<img
														src="<%=request.getContextPath()%>/conf_files/web-image/delete.png"
														border="0"
														onclick="deleteRow('orderRow<s:property value='formBean.flowOrder.productList.size()'/>');"
														style="cursor: pointer;" />
												</div></td>
										</tr>
									</tbody>
									<tr class="PBAInnerTableTitale">
										<th height="25" colspan="10" align='left'>合计</th>
										<th align='left'><s:textfield
												name="formBean.flowOrder.totalQuantity" id="totalQuantity"
												readonly="true" size="2" /></th>
										<th align='left'><s:textfield
												name="formBean.flowOrder.totalCost"
												id="totalCostOrder" readonly="true" size="2" /></th>
										<th align='left'><s:textfield
												name="formBean.flowOrder.totalInventoryQ"
												id="totalInventoryQ" readonly="true" size="2" /></th>
										<th align='left'><s:textfield
												name="formBean.flowOrder.totalQuantityDiff"
												id="totalQuantityDiff" readonly="true" size="2" /></th>
										<th></th>
										<th></th>
									</tr>
								</table>
							</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="30" colspan="7">
								<!-- table to show the footer of the chain inventory flow -->
								<table width="100%" align="left" border="0">
									<tr class="InnerTableContent">
										<td height="40">备注</td>
										<td colspan="2"><s:textfield
												name="formBean.flowOrder.comment" size="50" /></td>
									</tr>
									<tr class="InnerTableContent">
										<td height="40">盘点文件</td>
										<td colspan="2"><input type="file"
											name="formBean.inventory" id="inventory" /></td>
									</tr>
									<tr class="InnerTableContent">
										<td width="3%" height="25" align='left'>&nbsp;</td>
										<td width="3%" align='left'>&nbsp;</td>
										<td width="90%" align='left'><input type="button"
											value="存入草稿" onclick="saveDraft();" /> <input type="button"
											value="刷新电脑库存" onclick="calInventoryOrder();" /> <s:if
												test="formBean.flowOrder.id !=0">
												<input type="button" value="删除单据" onclick="deleteOrder();" />
											</s:if> <s:if test="formBean.flowOrder.id > 0">
												<input type="button" value="下载单据" onclick="downloadOrder();" />
											</s:if> <input type="button" value="一键纠正库存"
											onclick="oneKeyToAdjustInventory();"
											title="此功能将根据此库存单,自动添加报损单和报溢单达到纠正库存目的" /> <input
											type="button" value="库存扎帐"
											onclick="oneKeyToClearAndAdjustInventory();"
											title="此功能将会使用此库存单据,清空原始库存再根据此单自动添加报损单和报溢单达到纠正库存目的" /> <input
											type="button" value="生成最终报表" onclick="genInventoryReport();" />
											<input type="button" value="下载条码" onclick="getBarcodeFile();" />
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr class="InnerTableContent">
							<td height="4" colspan="7"><hr width="100%" color="#FFCC00" /></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</s:form>
	<s:form action="/action/headqInventoryFlowJSPAction!saveToDraft"
		method="POST" name="chainInventoryFlowForm2"
		id="chainInventoryFlowForm2" theme="simple">
		<s:hidden name="formBean.flowOrder.id" />
	</s:form>
</body>
</html>